home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / tutorials / tutorials.exe / frontend / flyfe / flyfe.cpp next >
Encoding:
C/C++ Source or Header  |  2000-12-15  |  2.6 KB  |  121 lines

  1. #include <windows.h>
  2. #include "..\..\lib\Fly3D.h"
  3.  
  4. char szTitle[100]="MyGame Title";
  5. char szWindowClass[100]="MyGame";
  6.  
  7. // loads the menu level
  8. void LoadLevel(HWND hWnd, HINSTANCE hInst)
  9. {
  10.     init_engine(hWnd,hInst,FLYAPPID_FLY);
  11.     init_directx();
  12.     init_render(FLY_RENDER_OPENGL);
  13.     
  14.     fullscreen=1;
  15.     rend->SetFullScreen();
  16.     
  17.     flyengine->open_fly_file("menu/menu.fly");
  18.     flyengine->init_texture_cache();
  19.     InvalidateRect(hFlyWnd, 0, 0);
  20. }
  21.  
  22. // main window message processing
  23. LRESULT CALLBACK WinFunc (HWND hWnd, UINT mens, WPARAM wParam, LPARAM lParam)
  24. {
  25.     switch (mens)
  26.     {
  27.     // window resize
  28.     case WM_SIZE:
  29.         if (rend)
  30.             rend->ResizeView(LOWORD(lParam),HIWORD(lParam));
  31.     break;
  32.  
  33.     // window activation
  34.     case WM_ACTIVATE:
  35.         if (flyengine)
  36.             if (LOWORD(wParam)==WA_INACTIVE || flyengine->con.mode)
  37.                 flyengine->noinput=1;
  38.             else flyengine->noinput=0;
  39.         break;
  40.  
  41.     // quit app
  42.     case WM_DESTROY:
  43.         PostQuitMessage (0);
  44.     break;
  45.     }
  46.  
  47.     return DefWindowProc (hWnd, mens, wParam, lParam);
  48. }
  49.  
  50. int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lp, int nCmd)
  51. {
  52.     WNDCLASS wcl;
  53.     MSG  msg;
  54.  
  55.     // register window class
  56.     wcl.style            = CS_HREDRAW | CS_VREDRAW;
  57.     wcl.lpfnWndProc        = (WNDPROC)WinFunc;
  58.     wcl.cbClsExtra        = 0;
  59.     wcl.cbWndExtra        = 0;
  60.     wcl.hInstance        = hInst;
  61.     wcl.hIcon            = LoadIcon(NULL, IDI_WINLOGO);
  62.     wcl.hCursor            = 0;
  63.     wcl.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
  64.     wcl.lpszMenuName    = NULL;
  65.     wcl.lpszClassName    = szWindowClass;
  66.     if (!RegisterClass (&wcl))
  67.     {
  68.       MessageBox (0, "Can't register Window", "ERROR", MB_OK);
  69.       return 0;
  70.     }
  71.  
  72.     // cerate main window
  73.     HWND hWndMain = CreateWindowEx(
  74.                             0,
  75.                             szWindowClass,
  76.                             szTitle,
  77.                             WS_POPUP,
  78.                             0, 0,
  79.                             GetSystemMetrics( SM_CXSCREEN ),
  80.                             GetSystemMetrics( SM_CYSCREEN ),
  81.                             NULL,
  82.                             NULL,
  83.                             hInst,
  84.                             NULL 
  85.                           );
  86.  
  87.     // load the level
  88.     ShowWindow (hWndMain, SW_MAXIMIZE);
  89.     LoadLevel (hWndMain, hInst);
  90.  
  91.     // main loop
  92.     while (1) 
  93.     {
  94.         while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE) 
  95.         {
  96.             if (GetMessage(&msg, NULL, 0, 0)) 
  97.                 {
  98.                 if (flyengine && (
  99.                     (msg.message==WM_KEYDOWN && msg.wParam==VK_ESCAPE) ||
  100.                     (msg.message==WM_CHAR && flyengine->con.mode && msg.wParam!=VK_ESCAPE)))
  101.                         flyengine->con.key_press(msg.wParam);
  102.                 TranslateMessage(&msg);
  103.                 DispatchMessage(&msg);
  104.                 }
  105.             else 
  106.                 {
  107.                 // frees engine, render, directx and quits app
  108.                 free_engine();
  109.                 free_render();
  110.                 free_directx();
  111.                 return TRUE;
  112.                 }
  113.             }
  114.         
  115.         if (rend && flyengine)
  116.             if (flyengine->step())    // simmulate
  117.                 rend->DrawView();   // draw view
  118.         }
  119. }
  120.  
  121.